<?php
/** Subclass to  myCharacter 
* @category		LevelManipulation
* @name			myLevelManager
* @description	Used to mange a Class to a given Character, can give/remove   MagicSlots,InventorySlots,FeatSlots,StatSlots
*/
class myLevelManager extends myCharacter{
	
	function __construct(){
		parent::__construct();
		// Add any specialized Construction Here ( Shouldnt be needed at this level. ) //
		
		
	}
	
	public function CanLevel($ClassName){
		$objClass = new $ClassName;
		if(!$this->HasExperinceNeededToLevel($objClass))
			return FALSE;
		if($this->GiveLevel($objClass))
			$this->CurrentEXP =  $this->CurrentEXP - $objClass->ExperinceNeededForNextLevel($this->Classes->{$objClass->Name}->Level);
		return TRUE;
	}
	
	private function GiveLevel($objClass){
		$this->Classes->{$objClass->Name}->Level++;
		$NewClassLevel = $this->Classes->{$objClass->Name}->Level;
		if($objClass->CanHaveMagicBonus())
			$this->MagicPoints 		=  $this->MagicPoints		+ $objClass->GetMagicPointIncrease($NewClassLevel);
		$this->InventorySlots 	=  $this->InventorySlots	+ $objClass->GetInventorySlotIncrease($NewClassLevel);
		$this->AbilityPoints 	  = $this->AbilityPoints 		+ $objClass->GetAbilityPointIncrease($NewClassLevel);
		$this->FeatPoints       = $this->FeatPoints			  + $objClass->GetFeatPointIncrease($NewClassLevel);
		$this->SaveCharacter();
		return TRUE;
			
	}
	private function HasExperinceNeededToLevel($objClass){
		if(! $ExperinceNeededToLevel = $objClass->ExperinceNeededForNextLevel($this->Classes->{$objClass->Name}->Level+1))
			$this->ReturnError("Unable to determine EXP needed to level {$objClass->Name}.");

		if($this->CurrentEXP < $ExperinceNeededToLevel){
			$ExperinceDiffernce = $ExperinceNeededToLevel - $this->CurrentEXP ;
			$this->ReturnError("Unable to gain additional level as {$objClass->Name}: You need  {$ExperinceDiffernce} more EXP to level this class.");
		}
		return TRUE;
	}
	
	
}

?>